package com.zhu.work;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class YmsURLConnection extends URLConnection {

    protected URL url;
    /**
     * Constructs a URL connection to the specified URL. A connection to
     * the object referenced by the URL is not created.
     *
     * @param url the specified URL.
     */
    protected YmsURLConnection(URL url) {
        super(url);
        this.url=url;
    }



    @Override
    public InputStream getInputStream() throws IOException {
        YmsFileBuffer buffer = YmsFileCache.getInstance().getFileBufferByFilePath(url.getFile());
        if(buffer!=null){
            return new ByteArrayInputStream(buffer.getContext());
        }else{
            return new FileInputStream(url.getFile());
        }
    }

    /**
     * yms缓存不需要打开任何连接
     * @throws IOException
     */
    @Override
    public void connect() throws IOException {
    }
}
